1. Field of the Invention
The present invention relates to an image data compression-coding technique.
2. Description of the Related Art
To compress a still image, conventionally, JPEG schemes using discrete cosine transform or schemes using Wavelet transform are often used. An encoding scheme of this type is a variable length encoding scheme which changes the code amount depending on the encoding target image.
The JPEG scheme as an international standard can define only one set of quantization matrices for an image of one page. Hence, when a document is scanned, and its image data is encoded, the resultant encoded data amount may exceed the expected target code amount.
If the code amount has exceeded the expected amount, commonly, the quantization matrices are changed to change the compression ratio, and the document is re-read. There is also a method of estimating the code amount by prescanning and resetting quantization parameters to adjust the code amount.
As a known code amount control scheme with prescanning, for example, precompressed data is stored in an internal buffer memory and decompressed. After changing the compression parameters, the data is fully compressed and output to an external storage device. The compression ratio of the full compression needs to be slightly higher than that of precompression.
Another scheme is also known in which, for example, the allowable code amount of each pixel block is obtained. To decrease the code amount, a coefficient is obtained by level-shifting a DCT coefficient n times and Huffman-coded. The shift amount n is decided on the basis of the allowable code amount.
A method of effectively generating encoded data within a predetermined size by single image input is also usable (e.g., Japanese Patent Laid-Open No. 2003-8903). In this technique, two memories to store encoded data are prepared, and generated encoded data is stored in both memories. When the amount of stored encoded data has reached target data amount, a large quantization step to obtain a high compression ratio is set. Simultaneously, one memory (first memory) is cleared. This raises the compression ratio for encoding after reaching the target data amount. The other memory (second memory) stores encoded data before the generated code amount reaches the target data amount. Hence, the data is re-encoded by using a higher quantization step, and the re-encoded result is stored in the first memory. This process is repeated every time the data amount reaches the target data amount.
Not only these lossy schemes but also lossless encoding schemes are also usable. A lossless encoding scheme is used for a non-natural image such as a character image or line image, and a lossy encoding scheme issued for a natural image part. In this method, the attribute of each image part is determined in advance. The encoding scheme is switched on the basis of the determination result (e.g., Japanese Patent Laid-Open No. 7-123273).
However, the lossy process cannot guarantee a high image quality for all kinds of images. If the data amount has exceeded the target code amount, the compression ratio of the entire image is uniformly raised by using a larger quantization step. This degrades the image at a high probability. Especially compression-coding of an image containing both a character/line image and a natural image poses many problems. This is because raising the quantization step rarely affects the quality of a natural image but makes the edge of a character/line image unclear.
From this viewpoint, each image area is preferably encoded by a scheme specific to it. That is, lossless encoding is executed for a character/line image, whereas lossy encoding is executed for a natural image. However, to implement this method, it is necessary to execute an attribute determination process of each area as a preprocess. The determination requires a high accuracy. Hence, the process executed by the apparatus inevitably becomes complex, resulting in a high cost.
Ideally, the whole area of one page is losslessly encoded. In lossless encoding, compressed image data can completely be reconstructed to document image data in principle. In lossless encoding, however, the compression ratio is nonadjustable, unlike lossy encoding. Hence, if the encoded data amount obtained by lossless encoding exceeds the target code amount, it is difficult to take a further measure.
Alternatively, lossless encoding is executed in the first scanning, and if the result has exceeded the target code amount, lossy encoding may be executed. In lossy encoding, however, only one quantization step is used for the whole area of one page, as described above. Hence, the image quality of a character/line image area in a document image unavoidably degrades depending on the employed quantization matrix.